package com.kaizeli.website.controller;

import com.kaizeli.website.pojo.entity.TravelExpense;
import com.kaizeli.website.pojo.dto.TravelExpenseDTO;
import com.kaizeli.website.response.Result;
import com.kaizeli.website.service.TravelExpenseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * 差旅费用控制器
 */
@Tag(name = "差旅费用管理", description = "差旅费用相关接口")
@RestController
@RequestMapping("/api/travel-expense")
public class TravelExpenseController {

    @Autowired
    private TravelExpenseService travelExpenseService;

    @Operation(summary = "根据验收节点ID查询差旅费用列表")
    @GetMapping("/acceptance/{acceptanceId}")
    public Result<List<TravelExpenseDTO>> getTravelExpensesByAcceptanceId(
            @Parameter(description = "验收节点ID") @PathVariable Long acceptanceId) {
        return travelExpenseService.getTravelExpensesByAcceptanceId(acceptanceId);
    }

    @Operation(summary = "根据员工ID查询差旅费用列表")
    @GetMapping("/employee/{employeeId}")
    public Result<List<TravelExpenseDTO>> getTravelExpensesByEmployeeId(
            @Parameter(description = "员工ID") @PathVariable Long employeeId) {
        return travelExpenseService.getTravelExpensesByEmployeeId(employeeId);
    }

    @Operation(summary = "根据项目ID查询差旅费用列表")
    @GetMapping("/project/{projectId}")
    public Result<List<TravelExpenseDTO>> getTravelExpensesByProjectId(
            @Parameter(description = "项目ID") @PathVariable Long projectId) {
        return travelExpenseService.getTravelExpensesByProjectId(projectId);
    }

    @Operation(summary = "创建差旅费用记录")
    @PostMapping
    public Result<TravelExpense> createTravelExpense(@RequestBody TravelExpense travelExpense) {
        return travelExpenseService.createTravelExpense(travelExpense);
    }

    @Operation(summary = "更新差旅费用记录")
    @PutMapping("/{id}")
    public Result<TravelExpense> updateTravelExpense(
            @Parameter(description = "差旅费用记录ID") @PathVariable Long id,
            @RequestBody TravelExpense travelExpense) {
        travelExpense.setId(id);
        return travelExpenseService.updateTravelExpense(travelExpense);
    }

    @Operation(summary = "审核差旅费用")
    @PostMapping("/{id}/review")
    public Result<Void> reviewTravelExpense(
            @Parameter(description = "差旅费用记录ID") @PathVariable Long id,
            @Parameter(description = "审核状态") @RequestParam String status) {
        return travelExpenseService.reviewTravelExpense(id, status);
    }

    @Operation(summary = "计算验收节点总差旅费用")
    @GetMapping("/acceptance/{acceptanceId}/total-amount")
    public Result<BigDecimal> calculateTotalTravelExpense(
            @Parameter(description = "验收节点ID") @PathVariable Long acceptanceId) {
        return travelExpenseService.calculateTotalTravelExpense(acceptanceId);
    }

    @Operation(summary = "批量创建差旅费用记录")
    @PostMapping("/batch")
    public Result<Void> batchCreateTravelExpenses(@RequestBody List<TravelExpense> travelExpenses) {
        return travelExpenseService.batchCreateTravelExpenses(travelExpenses);
    }
}
